<template>
  <div class="container">
    <navbar
      class="de-navbar"
      :vaniconL="true"
      :vaniconR="true"
      :noRight="true"
      :noLeft="false"
      iconNameL="arrow-left"
      iconNameR="search"
      @clickLeft="goBaCK"
      :bgcolor="
        $route.params.platform == 1 ? 'rgb(55, 81, 255) !important' : ''
      "
      :bgImage="
        $route.params.platform == 1
          ? 'linear-gradient(rgb(55, 81, 255) 0%, rgb(76, 99, 255) 50%, rgb(91 112 255) 75%, rgb(107 127 255) 100%) !important'
          : ''
      "
      >{{ $t("report.ai_report") }}</navbar
    >
    <div style="height: 0.45rem"></div>
    <div class="card">
      <div class="name">
        <img src="@/assets/images/medicine_box.png" alt />
        <!-- <span>{{detailData.info ? detailData.info.realName:'--/--'}}</span> -->
        <span>***</span>
      </div>
      <van-divider content-position="center">{{
        $t("detailList.details")
      }}</van-divider>
      <div class="mes">
        <div class="box">
          <p>
            <span>{{ $t("detailList.gender") }}:</span>
            {{
              detailData.info
                ? detailData.info.gender == 1
                  ? "男"
                  : detailData.info.gender == 2
                  ? "女"
                  : "*"
                : "--/--"
            }}
          </p>
          <p>
            <span>{{ $t("detailList.medical_card_number") }}:</span>
            {{ detailData.info ? detailData.info.medicalCardId : "--/--" }}
          </p>
          <p>
            <span>{{ $t("detailList.department") }}:</span>
            {{ detailData.info ? detailData.info.departmentName : "--/--" }}
          </p>
          <p>
            <span>{{ $t("detailList.drug_allergy") }}:</span>
            {{ detailData.info ? detailData.info.remark : "--/--" }}
          </p>
        </div>
        <div class="box">
          <p>
            <span>{{ $t("detailList.age") }}:</span>
            {{ detailData.info ? detailData.info.age : "--/--" }}
          </p>
          <p>
            <span>{{ $t("detailList.hospital_name") }}:</span>
            {{ detailData.info ? detailData.info.hospitalName : "--/--" }}
          </p>
          <p>
            <span>{{ $t("detailList.doctors") }}:</span>
            {{ detailData.info ? detailData.info.doctorName : "--/--" }}
          </p>
        </div>
      </div>
    </div>
    <van-divider>{{ $t("report.tips") }}</van-divider>
    <div class="report-box">
      <p class="title">{{ $t("report.report_text") }}:</p>
      <p
        class="report-text"
        v-html="reportText ? reportText : $t('report.text_tip')"
      ></p>
    </div>
    <div class="prob">
      <p>COVID-19</p>
      <p>{{ $t("report.prob") }} {{ (this.prob * 100).toFixed(2) }}%</p>
    </div>
    <div class="td-img">
      <p>四维肺部重构图</p>
      <van-icon
        v-if="tdStatus == 2"
        class="td-play"
        color="#292424"
        @click="tdShow"
        size="0.5rem"
        name="play-circle"
      />
      <van-image
        width="2rem"
        height="2rem"
        :src="
          tdData && tdStatus == 2
            ? tdData[0]
            : require('@/assets/images/4d.png')
        "
      />
    </div>
    <div class="chat">
      <p>{{ $t("report.desinty") }}</p>
      <ctArea :dsId="dsId"></ctArea>
    </div>
    <div class="chat" style="margin-bottom: 20px">
      <p>{{ $t("report.volumn") }}</p>
      <ctVolume :dsId="dsId"></ctVolume>
    </div>
    <van-popup class="td-show" v-model="tdFlag" @close="closeTd">
      <van-icon
        :name="nowFlag ? 'pause-circle-o' : 'play-circle-o'"
        class="pop-play"
        size="0.4rem"
        @click="popPlay"
      />
      <van-image
        @touchmove.prevent
        style="transform: scale(1.5)"
        width="3.5rem"
        :show-error="false"
        :show-loading="false"
        height="3.5rem"
        :src="tdImg ? tdImg : ''"
      />
    </van-popup>
  </div>
</template>

<script>
import navbar from "@/components/navbar";
import ctVolume from "@/views//components/ctVolume";
import ctArea from "@/views/components/ctArea";
import { getncpPatientInfo, getReportText } from "@/api/detailList.js";
import { get3DimgCount } from "@/api/covlist";
import { mapGetters } from "vuex";
export default {
  name: "reportDetail",
  components: { navbar, ctVolume, ctArea },
  data() {
    return {
      dsId: null,
      patientId: null,
      prob: null,
      detailData: [],
      reportText: null,
      tdData: null,
      tdFlag: false,
      tdImg: null,
      timer: null,
      tdStatus: null,
      nowIndex: 0,
      nowFlag: true,
    };
  },
  computed: {
    ...mapGetters(["pId", "dId"]),
  },
  watch: {},
  methods: {
    // 返回上一页
    goBaCK() {
      this.$router.push({
        name: "demoList",
        params: {
          platform: this.$route.params.platform,
        },
      });
    },

    // 获取数据
    getData(id) {
      getncpPatientInfo(id).then((res) => {
        if (res.status.code == 200) {
          this.detailData = res.data;
          // this.detailData.info.comment = this.detailData.info.comment.replace(
          //   /<.*?>/gi,
          //   ""
          // );
          this.detailData.dsResult.forEach((item) => {
            if (item.dsId == this.dsId) {
              this.prob = item.covidProb;
            }
          });
        }
      });
    },
    // 四维播放
    tdShow() {
      this.tdFlag = true;
      this.nowFlag = true;
      this.timer = setInterval(this.timeFun, 500);
    },
    // 定时器
    timeFun() {
      if (this.nowIndex == this.tdData.length) {
        this.nowIndex = 0;
      } else {
        this.tdImg = this.tdData[this.nowIndex++];
      }
    },
    // 关闭四维
    closeTd() {
      clearInterval(this.timer);
    },
    // 内部播放
    popPlay() {
      if (this.nowFlag) {
        clearInterval(this.timer);
        this.nowFlag = false;
      } else {
        this.timer = setInterval(this.timeFun, 500);
        this.nowFlag = true;
      }
    },
  },
  async created() {
    this.dsId = this.$route.params.dsId;
    this.patientId = this.$route.params.patientId;
    await this.getData(this.patientId);
    let reportRes = await getReportText(this.dsId);
    if (reportRes.status.code == 200) {
      this.reportText = reportRes.data.dsarr.comment
        ? reportRes.data.dsarr.comment.replace(/<.*?>/gi, "")
        : null;
    }
    let tdRes = await get3DimgCount(this.dsId);
    if (tdRes.status.code == 200) {
      this.tdStatus = tdRes.data.status;
      this.tdData = tdRes.data.dataimgname;
      this.tdData = this.tdData.map((item) => {
        return (item = `https://ds.pushiyixue.com/file/${this.dsId}/3D_viewing/${item}`);
      });
    }
  },
  mounted() {},
  beforeDestroy() {
    clearInterval(this.timer);
  },
  destroyed() {},
};
</script>
<style lang='scss' scoped>
@import "../../assets/css/utils";
.container {
  position: relative;
  height: 100vh;
  background: #f5f5f5;
  overflow-y: scroll;
  & .card {
    width: 94%;
    // height: 2rem;
    background: #ffffff;
    margin: 0 auto;
    margin-top: 10px;
    box-shadow: 0px 0px 10px #cccccc;
    & .van-divider {
      margin: 0;
      font-size: 0.14rem;
    }
    & .name {
      text-align: left;
      padding: 10px 15px;
      & img {
        width: 0.3rem;
        height: 0.3rem;
        vertical-align: middle;
      }
      & span {
        height: 0.22rem;
        vertical-align: middle;
        color: #4973d7;
        font-weight: 600;
        margin-left: 0.1rem;
        font-size: 0.2rem;
        display: inline-block;
        width: 2rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
    & .mes {
      display: flex;
      justify-content: flex-start;
      padding-bottom: 15px;
      & .box {
        margin: 0 0.3rem 0 0.15rem;
        text-align: left;
        & p {
          & span {
            color: #8d898e;
            font-size: 0.14rem;
          }
          margin: 10px 0;
          font-size: 0.14rem;
        }
      }
    }
  }
  & .van-divider {
    // margin: 0;
    font-size: 0.14rem;
  }
  & .prob {
    width: 94%;
    margin: 0 auto;
    margin-top: 10px;
    background: #ffffff;
    box-shadow: 0px 0px 10px #cccccc;
    margin-bottom: 10px;
    & p:nth-of-type(1) {
      font-size: 14px;
      padding: 10px;
      font-weight: bold;
    }
    & p:nth-of-type(2) {
      font-size: 16px;
      padding: 10px;
      color: #5573d0;
      font-weight: bold;
    }
  }
  & .td-img {
    width: 94%;
    margin: 0 auto;
    margin-bottom: 10px;
    box-shadow: 0px 0px 10px #cccccc;
    background: #ffffff;
    position: relative;
    & p {
      font-size: 0.14rem;
      padding: 0.1rem 0;
      color: #8d898e;
    }
    & .td-play {
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
      z-index: 1;
    }
  }
  & .chat {
    width: 94%;
    margin: 0 auto;
    margin-bottom: 10px;
    box-shadow: 0px 0px 10px #cccccc;
    background: #ffffff;
    & p {
      text-align: left;
      padding: 10px;
      font-size: 0.14rem;
      color: #686868;
    }
  }
}
.report-box {
  width: 94%;
  background: #ffffff;
  margin: 0 auto;
  margin-top: 10px;
  box-shadow: 0px 0px 10px #cccccc;
  & .title {
    color: #8d898e;
    font-size: 0.16rem;
    text-align: left;
    padding: 0.1rem 0.1rem 0 0.1rem;
  }
  & .report-text {
    text-align: left;
    padding: 0.15rem;
    color: #232323;
    font-size: 0.14rem;
    line-height: 0.2rem;
  }
}
.td-show {
  scrollbar-width: none; /* firefox */
  -ms-overflow-style: none; /* IE 10+ */
  overflow-x: hidden;
  overflow-y: hidden;
}
.td-show::-webkit-scrollbar {
  display: none; /* Chrome Safari */
}
.pop-play {
  position: absolute;
  right: 0;
  bottom: 0;
  z-index: 1;
}
</style>